package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.BankChargeRuleBiz;
import guda.stark.dal.dao.BankChargeRuleDAO;
import guda.stark.dal.dataobject.BankChargeRuleDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class BankChargeRuleBizImpl implements BankChargeRuleBiz{

    private final static Logger logger = LoggerFactory.getLogger(BankChargeRuleBizImpl.class);

    @Autowired
    private BankChargeRuleDAO bankChargeRuleDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            BankChargeRuleDO bankChargeRuleDO = bankChargeRuleDAO.getBankChargeRuleById(id);
            bizResult.data.put("bankChargeRuleDO", bankChargeRuleDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query BankChargeRule error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = bankChargeRuleDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<BankChargeRuleDO> bankChargeRuleList = bankChargeRuleDAO.selectForPage(baseQuery);
            bizResult.data.put("bankChargeRuleList", bankChargeRuleList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view BankChargeRule list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            bankChargeRuleDAO.delBankChargeRuleById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete bankChargeRule error", e);
        }
        return bizResult;
    }

    public BizResult create(BankChargeRuleDO bankChargeRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = bankChargeRuleDAO.insert(bankChargeRuleDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create BankChargeRule error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(BankChargeRuleDO bankChargeRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            bankChargeRuleDAO.updateByIdSelective(bankChargeRuleDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update BankChargeRule error", e);
        }
        return bizResult;
    }


}
